import * as types from './mutations-types'

const actions = {
  addCart ({commit}, product) {
    if (product.inventory > 0) {
      // 此处commit了types.ADD_TO_CART，cart和productList模块中对应的mutations方法都会执行
      commit(types.ADD_TO_CART, {
        id: product.id
      })
    }
  },
  removeCart ({commit}, { id }) {
    // 此处commit了types.ADD_TO_CART，cart和productList模块中对应的mutations方法都会执行
    commit(types.REMOVE_FROM_CART, {
      id
    })
  }
}

export default actions
